package com.qfedu.service.impl;

import com.qfedu.dao.UserDao;
import com.qfedu.entity.User;
import com.qfedu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author 刘浩
 * @Date 2020/8/11 20:24
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public User login(String code, String password) {
        User user = userDao.findByCode(code);
        System.out.println(user);
        if (user == null) {
            throw new RuntimeException("账户错误");
        }
        if (!user.getPassword().equals(password)) {
            throw new RuntimeException("密码错误");
        }
        return user;
    }

    @Override
    public void updateHeadImg(Integer uid, String imgPath) {
        User user = new User();
        user.setUid(uid);
        user.setImgPath(imgPath);
        userDao.update(user);
    }
}
